<?php
	/**
	 * 自动推送
	 * 网站用户未设置
	 */
	$Notice = M('Notice');$User = M('User');
	$where['flag'] = 1;
	$where['is_push'] = 1;
	$list = $Notice->where($where)->order('create_time asc')->select();
	if(count($list) != 0){
		foreach ($list as $key=>$val){
			import('COM.Core.Jpush');
			$jpush = new Jpush();
			if(empty($val['user_id'])){//全体通知
				$result = $jpush->jpushAll($val['message'],$val['type'],$val['ambulance']);
			}else{//个人通知
				$jpushId = $User->where('id = '.$val['user_id'])->getField('jpush_id');
				if(!empty($jpushId)){
					$result = $jpush->jpushByRegId($jpushId, $val['message'],$val['type'],$val['ambulance']);
				} 
			}
			$data['is_push'] = 2;
			$data['update_time'] = time();
			$Notice->where('id = '.$val['id'])->save($data);
		}
	}
	